<template>
  <div ref="chart" style="width: 600px; height: 400px;"></div>
</template>

<script>
export default {
  mounted() {
    this.initChart()
  },
  methods: {
    initChart() {
      // 获取DOM节点
      const chartDom = this.$refs.chart
      // 初始化图表
      const myChart = this.$echarts.init(chartDom)
      
      // 设置配置项
      const option = {
        title: {
          text: 'ECharts 入门示例'
        },
        tooltip: {},
        legend: {
          data: ['']
        },
        xAxis: {
          data: ['', '', '', '', '', '']
        },
        yAxis: {},
        series: [
          {
            name: '销量',
            type: 'bar',
            data: [5, 20, 36, 10, 10, 20]
          }
        ]
      }
      
      // 使用配置项显示图表
      myChart.setOption(option)
      
      // 响应式调整
      window.addEventListener('resize', function() {
        myChart.resize()
      })
    }
  }
}
</script>